package com.zxy.controller;

import com.zxy.common.result.Result;
import com.zxy.pojo.dto.TransferListQueryDTO;
import com.zxy.pojo.entity.SysUserBusinessStats;
import com.zxy.pojo.vo.PageResponseVO;
import com.zxy.service.TransferService;
import com.zxy.util.OperLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController

public class TransferController {
    @Autowired
    private TransferService transferService;



    /**
     * 转派管理-用户业务数据分页查询接口
     * 路径：GET /transfer/list
     * 参数：query参数（pageNum、pageSize、userId、userName、phonenumber、params[beginTime]、params[endTime]）
     */
    @GetMapping("/transfer/list")
    @OperLog(title = "转派管理",businessType = 0)
    public PageResponseVO<SysUserBusinessStats> getTransferList(
            // @Validated：触发TransferListQueryVO中的参数校验
            @Validated TransferListQueryDTO queryDTO
    ) {
        // 调用Service获取分页数据，返回泛型响应
        return transferService.getTransferList(queryDTO);
    }

    /**
     * 线索转派接口
     * 路径：PUT /transfer/assignment/{ids}/{userId}/{businessType}
     * 参数：路径参数（ids、userId、businessType）
     * 返回：转派结果
     */
    @PutMapping("/transfer/assignment/{ids}/{userId}/{businessType}")
    @OperLog(title = "转派结果",businessType = 0)
    public Result assignment(
            @PathVariable("ids") Long[] ids,
            @PathVariable("userId") Long userId,
            @PathVariable("businessType") Integer businessType
    ) {
        // 模拟实现转派逻辑
        // 根据业务类型进行不同的处理
        if (businessType == 1) {
            // 模拟已经分配了10条线索的情况
            Map<String, Object> data = new HashMap<>();
            data.put("msg", "线索转换失败！已经分配10 线索");
            data.put("flag", false);
            return Result.success(data);
        } else {
            // 转派成功的情况
            Map<String, Object> data = new HashMap<>();
            return Result.success(data);
        }
    }
}
